Ext.define('Service.role.view.RoleAuthTree',{
	extend: 'Ext.tree.Panel',
	alias: 'widget.Service_role_view_RoleAuthTree',
	
	scroll: 'both',
	style : {
		border : 'none'
	},
	animate: false,
	
	refreshTree: function(nodes){
		var me = this;
		var lRaws = [];
		Ext.each(nodes, function(node){
			var raw = node.raw;
			if(raw){
				delete raw.checked;
				lRaws.push(raw);
			}
		}, me);
		var root = me.getRootNode();
		var rootRaw = {
			id: root.data['id'],
			text: root.data['text'],
			moduleName: root.data['moduleName'],
			leaf: false
		}
		me.setChildren(lRaws, rootRaw);
		me.setRootNode(rootRaw);
	},
	
	setChildren: function(lRaws, pRaw){
		var me = this;
		var root = me.getRootNode();
		var children = [];
		for(var i in lRaws){
			if(lRaws[i].pname == pRaw.moduleName){
				children.push(lRaws[i]);
			}
		}
		pRaw.children = children;
		Ext.each(children, function(child){
			me.setChildren(lRaws, child);
		});
	},
    
	initComponent: function(){
		var me = this;
		Ext.applyIf(me,{
			store : new Ext.data.TreeStore({
				model: 'Service.role.model.AuthTreeModel',
				proxy : {
					type : 'memory'
				},
				root: {
					id : 1,
					text: '组织结构',
    				leaf: false,
    				moduleType: 0,
    				moduleText: '组织结构',
    				moduleName: 'root',
    				validFlag: true
				}
			})
		});
		me.callParent(arguments);
	}
});